<?php
class ContactController extends Zend_Controller_Action
{	
    public function init() {
        $SS = new Zend_Session_Namespace ('Default');
        Zend_Session::namespaceUnset('Default');
    }
    public function indexAction()
    {
        $this->view->title = "Liên hệ";
        try {
           //$contact = new Vina_Model_Contacts();
		   $model                  = new Vina_Model_Contacts();
           $form                   = new Default_Form_Contact();
           if ($this->_request->isPost()) {
                $formData = $this->_request->getPost();
    
                if ($form->isValid($formData)) {
                   $model->setName($formData['name']);
                   $model->setEmail($formData['email']);
                   $model->setMobile($formData['mobile']);
                   $model->setAddress($formData['address']);
                   $model->setFax($formData['fax']);
				   $model->setTitle($formData['title']);
				   $model->setContent($formData['content']);
                   $model->save();
                   $this->_redirect('/messages');
                }
            }
           //set view
           $modelConfig = new Vina_Model_Configs();
           $dataConfig = $modelConfig->find(1);
           $this->view->config = $dataConfig;
           $this->view->form       = $form;
        }catch(Exception $ex){
            echo "<pre>";
            print_r($ex->getMessage());
        }
    }
    public function registerAction(){
        $id = $this->_request->getParam('id',false);
        $this->view->title = "Đăng ký khóa học";
        try {
        $modelDev = new Vina_Model_DeveloperMapper();
        $dataCat = $modelDev->TreeMenu(41);
        $listIdCat[] = 41;
        foreach($dataCat as $vCat):
            $listIdCat[] = $vCat['id'];
        endforeach;
        $stringlistId = implode(',', $listIdCat);
        $news                    = new Vina_Model_News();
        $dataNews                = $news->fetchListToArray("category_id IN($stringlistId)", 'id desc');
            if ($this->_request->isPost()) {
                $formData = $this->_request->getPost();
                $modelRegister = new Vina_Model_Regiseter();
                $modelRegister->setName($formData['name']);
                $modelRegister->setBirthday($formData['birthday']);
                $modelRegister->setNoisinh($formData['noisinh']);
                $modelRegister->setJob($formData['job']);
                $modelRegister->setCompanyName($formData['company_name']);
                $modelRegister->setAddress($formData['address']);
                $modelRegister->setCity($formData['city']);
                $modelRegister->setEmail($formData['email']);
                $modelRegister->setPhone($formData['phone']);
                $modelRegister->setWebsite($formData['website']);
                $modelRegister->setClassName($formData['class_name']);
                $modelRegister->setClassWhere($formData['class_where']);
                $modelRegister->setContent($formData['content']);
                $modelRegister->setTime(time());
                $modelRegister->save();
                $this->_redirect('/messages');
            }
        
        $this->view->dataNews = $dataNews; 
        $this->view->idNews = $id;
        }catch(Exception $ex){
            echo "<pre>";
            print_r($ex->getMessage());
        }
    }
    	
}
